package com.nf.health.app.customview;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nf.health.app.R;

/**
 * Created by yuyahao
 */
public class CircleDialogFactory extends Dialog{
    private WindowManager wm;
    private TextView dialog_circle_factory_title;//title
    private Button btn_evaluate;//确认按钮的点击事件
    private TextView dialog_factor_circley_msg;//文本内容
    private LayoutInflater inflate;
    private View view;//加载的布局
    private  Display d;
    private RelativeLayout rl_content;
    private WindowManager.LayoutParams p;
    private LinearLayout ll_llcontextmsg;
    public CircleDialogFactory(Context context) {
        super(context, R.style.dialog3);
        init(context);
    }



    public CircleDialogFactory(Context context, AttributeSet attrs) {
        super(context, R.style.dialog3);
        // TODO Auto-generated constructor stub
        init(context);
    }
    public CircleDialogFactory(Context context, AttributeSet attrs, int defStyle) {
        super(context, R.style.dialog3);
        // TODO Auto-generated constructor stub
        init(context);
    }


    /****c初始化数据******/
    private void init(Context context) {
        //inflate = LayoutInflater.from(context);
        setContentView(R.layout.dialog_circle_factory);
        /*view = inflate.inflate(R.layout.dialog_circle_factory,null);
        setContentView(view);*/
        dialog_circle_factory_title = (TextView) findViewById(R.id.dialog_circle_factory_title);
        dialog_factor_circley_msg = (TextView) findViewById(R.id.dialog_factor_circley_msg);
        ll_llcontextmsg = (LinearLayout) findViewById(R.id.ll_llcontextmsg);
        rl_content = (RelativeLayout) findViewById(R.id.rl_content);
        btn_evaluate = (Button) findViewById(R.id.btn_evaluate);
       // setDialogSize();
        setCircleDialogAtter(0.45, 0.8);
    }

    /***
     * 设置内容显示的本文位置 居中显示
     * @return
     */
    public int getContentMsgCenter(){
        int contentMsgHeight = 0;
        dialog_factor_circley_msg.setGravity(Gravity.CENTER);
        ll_llcontextmsg.setGravity(Gravity.CENTER);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ll_llcontextmsg.getLayoutParams());
        params.gravity = Gravity.CENTER;
        ll_llcontextmsg.setLayoutParams(params);
        return contentMsgHeight;
    }
    /**
     * 设置dialog的大小和位置 ,不显示黑色的window的背景
     */
    private void setDialogSize(){
        wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        WindowManager m = getWindow().getWindowManager();
        d = m.getDefaultDisplay();  //为获取屏幕宽、高

        p = getWindow().getAttributes();  //获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.45);   //高度设置为屏幕的1.0
        p.width = (int) (d.getWidth() * 0.8);    //宽度设置为屏幕的0.8
        p.alpha = 1.0f;      //设置本身透明度
        p.dimAmount = 0.0f;      //设置黑暗度

        getWindow().setAttributes(p);     //设置生效
        getWindow().setGravity(Gravity.CENTER);       //设置对齐.
    }
    /***设置dialog的宽高，带有背景黑色的*****/
    public void setCircleDialogAtter(double widthValue, double heithValue){
        ViewGroup.LayoutParams para = rl_content.getLayoutParams();
        WindowManager m = getWindow().getWindowManager();
        d = m.getDefaultDisplay();  //为获取屏幕宽、高
        p = getWindow().getAttributes();  //获取对话框当前的参数值
        para.height = (int) (d.getHeight() * heithValue);;
        para.width = (int) (d.getWidth() * widthValue);
        rl_content.setLayoutParams(para);

    }
     /*
      设置dialog的大小和位置
     */
    public  void setDialogHigeht(double size){
        p.height = (int) (d.getHeight() * size);
        p.width = (int) (d.getWidth() * 0.8);    //宽度设置为屏幕的0.8
        p.alpha = 1.0f;      //设置本身透明度
        p.dimAmount = 0.0f;      //设置黑暗度

        getWindow().setAttributes(p);     //设置生效
        getWindow().setGravity(Gravity.CENTER);       //设置对齐
    }

    public CircleDialogFactory createCircleDialogFactory(String title,String msgContent,String buttonText,View.OnClickListener onClickListener){
        //CircleDialogFactory  dialog = new CircleDialogFactory(cnt);
        setCirclrDialogTitle(title);
        setCirclrDialogContent(msgContent);
        setCirclrDialogButtonText(buttonText);
        setCirclrDialogButtonText(onClickListener);
        return this;
    }
    /*********设置标题*********/
    public void setCirclrDialogTitle(String title){
        dialog_circle_factory_title.setText(TextUtils.isEmpty(title) ? "" : title);
    }
    /*********设置文本内容*********/
    public void setCirclrDialogContent(String msgContent){
        dialog_factor_circley_msg.setText(TextUtils.isEmpty(msgContent) ? "" : msgContent);
    }
    /*********设置按钮的文本********/
    public void setCirclrDialogButtonText(String buttonText){
        btn_evaluate.setText(TextUtils.isEmpty(buttonText) ? "" : buttonText);
    }
    /*********设置按钮的文本的点击事件********/
    public void setCirclrDialogButtonText(View.OnClickListener onClickListener){
        btn_evaluate.setOnClickListener(onClickListener);
    }
    /*********重载*******/
    public CircleDialogFactory createCircleDialogFactoryTitle(String title){
        setCirclrDialogTitle(title);
        return this;
    }
    public CircleDialogFactory setCircleDialogFactoryMsg(String msgContent){
        setCirclrDialogContent(msgContent);
        return this;
    }
    public CircleDialogFactory setCircleDialogFactoryOnClicklistener(View.OnClickListener onClickListener){
        setCirclrDialogButtonText(onClickListener);
        return this;
    }
    public CircleDialogFactory setCirclrDialogButtonSte(String buttonText){
        setCirclrDialogButtonText(buttonText);
        return this;
    }
}
